package com.example.easyscript.service.task;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.easyscript.dto.Req.AddImageReq;
import com.example.easyscript.entity.task.Image;
import com.example.easyscript.entity.task.StatusImage;
import com.example.easyscript.mapper.StatusImageMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
* @author huzixian
* @date  2023-03-08
*/
@Slf4j
@Service
public class StatusImageService extends ServiceImpl<StatusImageMapper, StatusImage>{

    @Resource
    private ImageService imageService;

    public List<String> getImageListByStatusId(Integer statusId) {
        List<Integer> imageIds = baseMapper.getImageListByStatusId(statusId);
        if(imageIds==null || imageIds.size()==0){
            return Collections.EMPTY_LIST;
        }
        List<String> imageUrls = imageService.getImageUrlListByIds(imageIds);
        return imageUrls;
    }

    public List<Image> getImagesByStatusId(Integer statusId){
        List<Integer> imageIds = baseMapper.getImageListByStatusId(statusId);
        List<Image> imageList = imageService.getImageList(imageIds);
        return imageList;
    }

    public void saveStatus(AddImageReq statusImageReq) {
        List<Integer> ids = statusImageReq.getImageIds();
        ids.forEach(item->{
            StatusImage buf = new StatusImage();
            buf.setImageId(item);
            buf.setStatusId(statusImageReq.getId());
            this.save(buf);
        });
    }
}
